//
//  LLPlayerView.m
//  AVPlayertest
//
//  Created by lzy on 17/2/8.
//  Copyright © 2017年 NumberFive. All rights reserved.
//

#import "LLPlayerView.h"

@interface LLPlayerView()

@end

@implementation LLPlayerView

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.pauseButton addTarget:self
                         action:@selector(pauseAction)
               forControlEvents:UIControlEventTouchUpInside];
}

- (void)pauseAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(pauseButtonClicked)]) {
        [self.delegate pauseButtonClicked];
    }
}

+ (instancetype)playerView {
    LLPlayerView *view = [[NSBundle mainBundle]  loadNibNamed:NSStringFromClass([self class])
                                                  owner:nil
                                                options:nil].firstObject;
    return view;
}

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:CGRectZero];
    if (self) {
        self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    }
    return self;
}

+ (Class )layerClass {
    return NSClassFromString(@"AVPlayerLayer");
}

- (void)setPlayer:(AVPlayer *)player {
    AVPlayerLayer *layer = (AVPlayerLayer *)self.layer;
    layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    layer.player = player;
}


@end
